package com.noble.glamour.ui.user.my.gift;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.noble.meether.R;
import com.noble.glamour.bean.my.GiftsList;
import com.noble.glamour.module.logic.baseui.ExBaseAdapter;
import com.noble.library.image.ImageLoader;

import java.util.List;

/**
 * 礼物列表
 */
public class MyGiftAdapter extends ExBaseAdapter<GiftsList.GiftInfo> {

    public MyGiftAdapter(Context context, List<GiftsList.GiftInfo> data) {
        super(context, data);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder holder;
        if (convertView == null) {
            convertView = inflate(R.layout.my_gift_item);
            holder = new MyViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyViewHolder) convertView.getTag();
        }
        final GiftsList.GiftInfo info = getItem(position);
        ImageLoader.loadCenterCrop(getContext(), info.getPic(), holder.gift_icon);
        holder.item_title.setText(info.getName());
        holder.item_time.setText(info.getTimeCreate());
        holder.item_num.setText("x" + info.getNum());
        return convertView;
    }

    private class MyViewHolder {
        private ImageView gift_icon;
        private TextView item_title, item_time, item_num;

        public MyViewHolder(View convertView) {
            initView(convertView);
        }

        private void initView(View convertView) {
            gift_icon = convertView.findViewById(R.id.gift_icon);
            item_title = convertView.findViewById(R.id.item_title);
            item_time = convertView.findViewById(R.id.item_time);
            item_num = convertView.findViewById(R.id.item_num);
        }
    }
}